﻿using Presenters.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Classroom
{
    /// <summary>
    /// Lógica de interacción para ClassroomObject.xaml
    /// </summary>
    public partial class ClassroomObject : Window, IClassroomObject
    {
        ClassroomObjectPresenter presenter;
        private string Message;
        Model.Classroom modify = new Model.Classroom();

        public ClassroomObject()
        {            
            InitializeComponent();
            this.ComboBox_status.SelectedIndex = 0;
            this.ComboBox_type.SelectedIndex = 0;
            presenter = new ClassroomObjectPresenter(this);
        }

        //Modify
        public ClassroomObject(Model.Classroom modifyObject)
        {
            InitializeComponent();
            presenter = new ClassroomObjectPresenter(this);
            this.Title = "Modificar materia";
            this.modify = modifyObject;
            
            fillAllCapmpus();
            this.TextBox_code.IsEnabled = false;            
            this.Button_NewClassroom.Visibility = Visibility.Hidden;
            this.Button_ModifyClassroom.Visibility = Visibility.Visible;
        }

        //View 
        public ClassroomObject(Model.Classroom modifyObject, string buttonText)
        {
            InitializeComponent();
            presenter = new ClassroomObjectPresenter(this);
            this.Title = "Ver materia";
            this.modify = modifyObject;

            fillAllCapmpus();
            this.Button_NewClassroom.Visibility = Visibility.Hidden;
            this.Button_Close.Content = buttonText;
        }

        public void fillAllCapmpus()
        {
            this.TextBox_capacity.Text = modify.capacity.ToString();
            this.TextBox_code.Text = modify.code;
            this.ComboBox_status.SelectedValue = modify.status;
            this.ComboBox_type.SelectedValue = modify.type;            
        }

        public string code
        {
            get { return (this.TextBox_code.Text); } 
        }
        public char type
        {
            get { return (Convert.ToChar(ComboBox_type.SelectedValue.ToString())); }
        }
        public char status
        {
            get { return (Convert.ToChar(ComboBox_status.SelectedValue.ToString())); }
        }
        public int capacity
        {
            get { return (Convert.ToInt16(TextBox_capacity.Text)); }
        }
        public string message
        {
            set { Message = value; }
        }

        private void Button_Click_Close(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Button_Click_NewClassroom(object sender, RoutedEventArgs e)
        {
            presenter.SubmitNewClassroom();
            MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);            
        }

        private void Button_Click_ModifyClassroom(object sender, RoutedEventArgs e)
        {
            presenter.SubmitModifyClassroom();
            MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);            
        }
    }
}
